package com.zhao.controller;

import com.zhao.entity.User;
import com.zhao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("findAll")
    List<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("findById/{id}")
    User findById(@PathVariable("id") String id) {
        return userService.findById(id);
    }

    @GetMapping("deleteUserById/{id}")
    void deleteUserById(@PathVariable("id") String id) {
        userService.deleteUserById(id);
    }

    @GetMapping("updateUserById/{id}")
    void updateUserById(@PathVariable("id") String id) {
        userService.updateUserById(id);
    }

    @GetMapping("addUserById/{id}")
    void addUserById(@PathVariable("id") String id) {
        User user = new User();
        user.setName("张三").setAge(16).setSalary(20000d).setId(id);
        userService.addUser(user);
    }

    @GetMapping("getUserAndPosition/{id}")
    void getUserAndPosition(@PathVariable("id") String id) {
        userService.getUserAndPosition(id);
    }
}
